Typical HAL CEC use cases for migration

This section provides information about typical HAL CEC use cases for migration.

Use case: CEC transmit IT mode

This use case describes how to transmit a CEC frame in Interrupt mode (IT mode) using HAL1 and HAL2.

Sequence diagram

@startuml

' Fix order of each column
participant "User application" as user
participant "<b>HAL CEC driver</b>"       as cec
participant "CEC IRQ handler" as isr

== CEC initialization / configuration ==
user -> cec : <color #Blue> HAL_CEC_Init</color>( hcec)
note right: <color #Blue>  Initializes the CEC mode according to the specified parameters in the handle.
cec --> user: HAL_OK
...

== CEC control ==
user ->cec : <color #Blue> HAL_CEC_Transmit_IT</color>( hcec, InitiatorAddress, DestinationAddress, pData, Size )
note right: <font color=blue> transmit the frame in IT mode:\n <font color=blue>- the IRQ handler processes, byte per byte, the full frame transmission.
cec --> user: HAL_OK

== CEC transmission ==
isr -> cec : <font color=orange> HAL_CEC_IRQHandler()
note right: <font color=orange> interrupt when Tx event occurs
cec -> user : <font color=orange> HAL_CEC_TxCpltCallback() </font> user process for CEC Tx
...


group If hardware error occurs :

== CEC transmit error handling ==
 alt Tx error detected
   box "Tx error handling" #LightYellow
   isr -> cec : <font color=orange> HAL_CEC_IRQHandler()
   note right: <font color=orange> interrupt when error: \n- Tx error
   cec -> user : <font color=orange> HAL_CEC_ErrorCallback() </font> user process CEC line error
   end box
 end

group If hardware error occurs :


@enduml

Code snippet

HAL1

HAL2

CEC_HandleTypeDef                   hcec;
uint8_t                             Tab_Tx[2];
uint8_t                             DestinationAddress;
uint8_t                             InitiatorAddress;
uint32_t                            TxSize = 0X02;





hcec.Instance                       = CEC;


hcec.Init.OwnAddress                = CEC_OWN_ADDRESS_1;
HAL_CEC_Init(&hcec);



InitiatorAddress   = 0x1;
DestinationAddress = 0x3;
Tab_Tx[0] = 0x44;
Tab_Tx[1] = 0x42;
HAL_CEC_Transmit_IT(&hcec, InitiatorAddress, DestinationAddress, (uint8_t *)&Tab_Tx, TxSize);
hal_cec_handle_t                    hcec;
uint8_t                             tx_data_frame[2];
hal_cec_header_t                    tx_header;

hal_cec_header_t                    p_rx_header;
uint8_t                             rx_data_frame[2];
uint32_t                            max_size_byte = 0x02;

uint32_t                            tx_size  = 0x02;
hal_cec_config_t                    config;

HAL_CEC_Init(&hcec, HAL_CEC);

config.own_address = HAL_CEC_OWN_ADDR_1;
HAL_CEC_SetConfig(&hcec, &config);

/* Start CEC in IT mode to enable the peripheral */
HAL_CEC_Start_IT(&hcec, &p_rx_header, rx_data_frame, max_size_byte);

tx_header.initiator_address   = 0x1;
tx_header.destination_address = 0x3;
tx_data_frame[0] = 0x44;
tx_data_frame[1] = 0x42;
HAL_CEC_Transmit_IT(&hcec, &tx_header, tx_data_frame, tx_size);

Key changes

  1. HAL2 separates initialization from configuration using HAL_CEC_Init then HAL_CEC_SetConfig.

  2. HAL2 requires starting the peripheral in IT mode using HAL_CEC_Start_IT before transmitting.

  3. HAL2 uses typed configuration and header structures (for example hal_cec_config_t and hal_cec_header_t) instead of passing raw addressing parameters.


Use case: CEC receive IT mode

This use case describes how to receive a CEC frame in Interrupt mode (IT mode) using HAL1 and HAL2.

Sequence diagram

@startuml

' Fix order of each column
participant "User application" as user
participant "<b>HAL CEC driver</b>"       as cec
participant "CEC IRQ handler" as isr

== CEC initialization / configuration / optional configuration / control ==

user -> cec : <color #Blue> HAL_CEC_Init</color>(hcec)
note right: <color #Blue>  Initializes the CEC mode according to the specified parameters in the handle.
cec --> user: HAL_OK
== CEC reception ==

isr -> cec : <font color=orange> HAL_CEC_IRQHandler()
note right: <font color=orange> interrupt when Rx event occurs
cec -> user : <font color=orange> HAL_CEC_RxCpltCallback() </font> user process for CEC Rx
...

note over user: <color #Blue> The user application has to: \n\
<color #Blue> copy the received data frame \n and can \n <color #Blue>swap the buffer pointer with HAL_CEC_ChangeRxBuffer( hcec, Rxbuffer )

group optional
user -> cec : <color #Blue> HAL_CEC_ChangeRxBuffer</color>( hcec, Rxbuffer )
note right: <color #Blue> set a new buffer pointer using HAL_CEC_ChangeRxBuffer()\n <color #Blue>within HAL_CEC_RxCpltCallback()
cec --> user: HAL_OK
end
...

== CEC reception error handling ==
group If hardware error occurs :

 alt Rx error detected
   box "Rx error handling" #LightYellow
    isr -> cec : <font color=orange> HAL_CEC_IRQHandler()
    note right: <font color=orange> interrupt when error
    cec -> user : <font color=orange> HAL_CEC_ErrorCallback() </font> user process CEC line error
   end box
 end

@enduml

Code snippet

HAL1

HAL2

CEC_HandleTypeDef                   hcec;
uint8_t                             Tab_Rx[3];
uint8_t                             New_RxBuffer[3];




hcec.Instance                       = CEC;


hcec.Init.OwnAddress                = CEC_OWN_ADDRESS_3;



hcec.Init.SignalFreeTime            = CEC_DEFAULT_SFT;
hcec.Init.Tolerance                 = CEC_STANDARD_TOLERANCE;
hcec.Init.BRERxStop                 = CEC_RX_STOP_ON_BRE;
hcec.Init.BREErrorBitGen            = CEC_BRE_ERRORBIT_GENERATION;
hcec.Init.LBPEErrorBitGen           = CEC_LBPE_ERRORBIT_GENERATION;
hcec.Init.BroadcastMsgNoErrorBitGen = CEC_BROADCASTERROR_ERRORBIT_GENERATION;
hcec.Init.SignalFreeTimeOption      = CEC_SFT_START_ON_TXSOM;
hcec.Init.ListenMode                = CEC_FULL_LISTENING_MODE;

hcec.Init.RxBuffer                  = Tab_Rx;
HAL_CEC_Init(hcec);

/* After Rx complete */
HAL_CEC_RxCpltCallback(&hcec)
{
  HAL_CEC_ChangeRxBuffer(&hcec, New_RxBuffer);
}
hal_cec_handle_t                    hcec;
uint8_t                             rx_data_frame[2];
uint8_t                             new_rx_data_frame[2];
hal_cec_header_t                    p_rx_header;

uint32_t                            max_size_byte = 0x02;
hal_cec_config_t                    config;

HAL_CEC_Init(&hcec, HAL_CEC);

config.own_address = HAL_CEC_OWN_ADDR_5;
HAL_CEC_SetConfig(&hcec, &config);


/* Optional configurations */
HAL_CEC_SetSignalFreeTimeDuration(&hcec, HAL_CEC_SIG_FREETIME_DURATION_AUTO);
HAL_CEC_SetRxTolerance(&hcec, HAL_CEC_RX_TOLERANCE_STANDARD);
HAL_CEC_EnableRxStopUponBitRisingErr(&hcec);
HAL_CEC_EnableBitRisingErrGen(&hcec);
HAL_CEC_EnableLongBitPeriodErrGen(&hcec);
HAL_CEC_EnableBroadcastErrGen(&hcec);
HAL_CEC_SetSignalFreeTimeStart(&hcec, HAL_CEC_SIG_FREETIME_ON_MSG_START);
HAL_CEC_SetListenMode(&hcec, HAL_CEC_LISTEN_MODE_RECEIVE_ALL_MSG);

HAL_CEC_Start_IT(&hcec, &p_rx_header, rx_data_frame, max_size_byte);

/* After Rx complete */
HAL_CEC_RxCpltCallback(&hcec)
{
  HAL_CEC_SetRxBuffer(&hcec, &p_rx_header, new_rx_data_frame, max_size_byte);
}

Key changes

  1. In HAL2, optional RX-related settings are configured through dedicated APIs (for example HAL_CEC_SetRxTolerance) rather than through handle init fields.

  2. In HAL2, reception is started with HAL_CEC_Start_IT and the RX buffer can be updated using HAL_CEC_SetRxBuffer.

  3. HAL2 uses typed configuration structures (for example hal_cec_config_t and hal_cec_header_t) and buffers passed as parameters.